package Generator;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;

import javax.swing.JFileChooser;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;


public class HTMLtoJava {

        
        public static void convertir(String ruta) throws IOException
        {
                PrintWriter pr= new PrintWriter(new FileOutputStream(ruta+"-1"));
                BufferedReader bf= new BufferedReader(new FileReader(ruta));
                
                String linea= bf.readLine();
                
                while(linea!=null)
                {
                        String nuevaLinea="";
                        char[] carac=linea.toCharArray();
                        for(int i=0; i<carac.length; i++)
                        {
                                nuevaLinea+=(carac[i]=='"')?("\\\""):(carac[i]);
                        }
                        nuevaLinea="pr.println(\""+nuevaLinea+"\");";
                        pr.println(nuevaLinea);
                        linea=bf.readLine();
                }
                
                bf.close();
                pr.close();
        }
        
        /**
         * @param args
         */
        public static void main(String[] args) {
                try {
                        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                } catch (ClassNotFoundException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                } catch (InstantiationException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                } catch (IllegalAccessException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                } catch (UnsupportedLookAndFeelException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                }

                 JFileChooser fc = new JFileChooser( );
                fc.setDialogTitle( "Abrir archivo html" );
                int resultado = fc.showOpenDialog( null );
                if( resultado == JFileChooser.APPROVE_OPTION )
                {
                    File archivo = fc.getSelectedFile( );
                    try {
                                        convertir(archivo.getAbsolutePath());
                                } catch (IOException e) {
                                        e.printStackTrace();
                                }
                }

        }

}
